package edu.chl.chrfra.backing;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.validation.constraints.*;
//import org.primefaces.event.FileUploadEvent;

@ManagedBean
@RequestScoped
public class AddProductBackingBean implements Serializable {
    /* private String s = (new SimpleDateFormat("yyyy")).format(new GregorianCalendar().getTime());
    final int max = Integer.parseInt(s);*/

    @Size(min = 3, message = "Name must be at least 3 characters long.")
    @NotNull(message = "Name cannot be empty.")
    private String prodName;
    @NotNull(message = "Category cannot be empty.")
    private String catName;
    @NotNull
    @Digits(fraction = Integer.MAX_VALUE, integer = Integer.MAX_VALUE, message = "Price must be a number.")
    private Double price;
    @NotNull
    //@Digits(fraction = Integer.MAX_VALUE, integer = Integer.MAX_VALUE, message = "Price must be a number.")
    /*@Max(max)*/
    @Digits(fraction = Integer.MAX_VALUE, integer = Integer.MAX_VALUE, message = "Year must be a number.")
    private int year;
    @NotNull
    @Digits(fraction = Integer.MAX_VALUE, integer = Integer.MAX_VALUE, message = "Mileage must be a number.")
    private int mileage;
    
    //private byte[] image;

    public String getCatName() {
        return catName;
    }

    public Double getPrice() {
        return price;
    }

    public int getMileage() {
        return mileage;
    }

    public void setMileage(int mileage) {
        this.mileage = mileage;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getProdName() {
        return prodName;
    }

    public void setCatName(String catName) {
        this.catName = catName;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public void setProdName(String prodName) {
        this.prodName = prodName;
    }
/*
    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }*/
/*
    public void handleFileUpload(FileUploadEvent event) {
        // TODO: Connect to user, add an Image object
        Logger.getAnonymousLogger().log(Level.INFO, String.format("BILD**********************************", "HAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
        image = event.getFile().getContents();
        Logger.getAnonymousLogger().log(Level.INFO, String.format("BILD**********************************%d", image.length));
        System.out.println("Uploaded: " + event.getFile().getFileName());
        Logger.getAnonymousLogger().log(Level.INFO, String.format("'%s' upload of size %d.", event.getFile().getFileName(), event.getFile().getSize()));

        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);

        String ext = event.getFile().getFileName().split("\\.")[0];
        Logger.getAnonymousLogger().log(Level.INFO, String.format("Extension: %s", ext));
    }*/

    /** Creates a new instance of ViewCartBacking */
    public AddProductBackingBean() {
    }
}
